<?php
	
require_once dirname(__FILE__) . '/PgSQL.php';

if (isset($_GET['fid'])) {
	$fid = $_GET['fid'];
	$splited = preg_split("/\./", $fid);
	$id = $splited[1];
}

$queryStr = "SELECT * FROM dnhotel WHERE gid = ".$id;
// Khởi tạo đối tượng PgSQL
$pg = new PgSQL();
$pg->connect();
$result = $pg->query($queryStr);
$html = "";
if ($pg->numberRows() != 0) {
	if ($row = pg_fetch_object($result)) {
		$html = '<form id="hotelInfo" name="hotelInfo" method="post" action="">
			<fieldset>
				<legend>'.$row->name.'</legend>
				<div>
					<label>Địa chỉ: '.$row->address.'</label>
				</div>
				<div>
					<img src="images/phone.png" height="20" width="20"> 
					'.$row->phone.'
				</div>
				<div>
					<a href="http://'.$row->website.'" target="_blank">'.$row->website.'</a>
				</div>
				<div>';
		if (!empty($row->star))
		{
			for ($i=1; $i<=$row->star; $i++)
			{
				$html .= '<img src="images/star.png" height="20" width="20"> ';
			}
		}
		$sql = 'SELECT COUNT(*) FROM comment WHERE id='.$row->id;
		$count = $pg->query($sql);
		$html .= '</div><a href="comment.php?id='.$row->id.'" target="_blank">Nhận xét('.pg_fetch_object($count)->count.')</a>';
		$html .= '</fieldset>
		</form>';
	}
} else {
	$html = "<p>Không tìm thấy thông tin khách sạn này</p>";
}
$pg->disconnect();

echo $html;

?>